package com.hsm2;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;

public class TestIter {
    public static void main(String[] args) {
        ArrayList<String> al = new ArrayList<>();
        al.add("aaa");
        al.add("bbb");
        al.add("ccc");
        al.add("ddd");
        al.add("eee");
        //迭代器遍历

        /*Iterator it = al.iterator();
        while(it.hasNext()){
           if("ccc"==it.next()){
               al.add("kkk");
           }
        }*/
        ListIterator<String> it = al.listIterator();
        while(it.hasNext()){
            if("ccc".equals(it.next())){
                it.add("kkk");
            }

        }
        //判断下面贺上面有没有元素
        System.out.println(it.hasNext());
          //可以用来逆向遍历
        System.out.println(it.hasPrevious());
        System.out.println(al);
    }
}
